﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Mvc;

namespace BenlaiStudy.Controllers
{
    public class UIController : BaseController
    {
        //
        // GET: /UI/
        public ActionResult Index()
        {
            return View();
        }

        //
        // GET: /UI/Grid
        public ActionResult Grid()
        {
            ViewBag.MenuNo = 10030001;
            return View();
        }

        //
        // GET: /UI/GridRowBind
        public ActionResult GridRowBind()
        {
            return View();
        }

        //
        // GET: /UI/GridPager
        public ActionResult GridPager()
        {
            return View();
        }
        
        //
        // GET: /UI/GridPager
        public ActionResult GridEdit()
        {
            return View();
        }
        
        //
        // GET: /UI/JQTree
        public ActionResult JQTree()
        {
            ViewBag.MenuNo = 10030002;
            return View();
        }

        #region Upload Images

        //
        // GET: /UI/UploadImage
        public ActionResult UploadImage()
        {
            return View();
        }

        //
        // GET: /UI/UploadImage
        public ActionResult UploadFile()
        {
            return View();
        }

        //
        // POST: /UI/UploadImages
        public ActionResult UploadImages()
        {
            StringBuilder info = new StringBuilder();
            foreach (string file in Request.Files)
            {
                string fileName = Request.Form["FileName"];
                string savePath = Request.Form["SavePath"];

                savePath += fileName.Substring(0, fileName.LastIndexOf('/') + 1);
                fileName = fileName.Substring(fileName.LastIndexOf('/') + 1);

                HttpPostedFileBase postFile = Request.Files[file];//get post file 
                if (postFile.ContentLength == 0)
                    continue;
                
                postFile.SaveAs(savePath + fileName);//save file 
                info.AppendFormat("Upload File:{0}/r/n", fileName);//info 


                //string newFilePath = Server.MapPath(@"/App_Data/UploadImage/");//save path 
                //postFile.SaveAs(newFilePath + Path.GetFileName(postFile.FileName));//save file 
                //info.AppendFormat("Upload File:{0}/r/n", postFile.FileName);//info 
            }
            ViewData["Info"] = info;
            return RedirectToAction("UploadImage");
        }

        #endregion

        public ActionResult Editor()
        {
            ViewBag.MenuNo = 10030003;
            return View();
        }

    }
}
